In [120]:
%less ./data/jacoco.csv
In [30]:
import pandas as pd
coverage = pd.read_csv("./data/jacoco.csv")[['PACKAGE', 'CLASS', 'LINE_COVERED', 'LINE_MISSED']]
coverage.head()
Out[30]:
In [36]:
coverage['lines'] = coverage.LINE_COVERED + coverage.LINE_MISSED
coverage['coverage'] = coverage.LINE_COVERED / coverage.lines
coverage.head()
Out[36]:
In [40]:
%matplotlib inline
coverage.groupby("PACKAGE").mean()['coverage'].plot(kind='barh')
Out[40]:
In [43]:
coverage['fqn'] = coverage.PACKAGE + "." + coverage.CLASS
coverage[['fqn', 'lines']].head()
Out[43]:
In [44]:
import py2neo
graph = py2neo.Graph()
query="""
MATCH
(p:Package)-[:CONTAINS]->(c:Class)<-[DEPENDS_ON]-(c2:Class)<-[:CONTAINS]-(p2:Package)
WHERE p.fqn = "org.springframework.samples.petclinic.repository.jdbc" AND p <> p2
RETURN DISTINCT c.fqn, c2.fqn
"""
graph.data(query)
Out[44]:
Laden der Coverage-Informationen in die Graphdatenbank
In [51]:
query="""
UNWIND {coverage_data} as coverage
MATCH (c:Class)
WHERE c.fqn = coverage.fqn
MERGE (c)-[:HAS_MEASURE]->(m)
SET
m:Measure:Coverage,
m.lineCoverage = coverage.coverage
RETURN c.fqn, m.lineCoverage
"""
result = graph.run(query, coverage_data=coverage.to_dict(orient='records')).data()
pd.DataFrame(result).head()
Out[51]:
In [53]:
query = """
MATCH
(n:Subdomain)
<-[:BELONGS_TO]-
(c:Class)
-[:HAS_MEASURE]->
(m:Coverage)
RETURN n.name as subdomain, AVG(m.lineCoverage) as covered_lines
ORDER BY covered_lines
"""
pd.DataFrame(graph.data(query), columns=['subdomain','covered_lines'])
Out[53]:
Identifying code to delete
In [21]:
query="""
MATCH
(s1:Subdomain)<-[:BELONGS_TO]-
(type:Type)-[r:DEPENDS_ON*0..1]->
(dependency:Type)-[:BELONGS_TO]->(s2:Subdomain),
(type)-[:HAS_MEASURE]->(c:Coverage)
RETURN s1.name as from, s2.name as to, SUM(c.value) as x_number
"""
result = graph.run(query).data()
df = pd.DataFrame(result)
df.head()
Out[21]:
In [22]:
import json
json_data = df.to_dict(orient='split')['data']
with open ( "vis/chord_deletion_data.json", mode='w') as json_file:
json_file.write(json.dumps(json_data, indent=3))
json_data[:5]
Out[22]:
In [ ]:
query="""
MATCH (p:Package)-[:CONTAINS]->(c:Class)<-[:DEPENDS_ON]-(d:Class),
(d)<-[:CONTAINS]-(p2),
(c)-[:HAS_MEASURE]->(m:Measure:Coverage)
WITH p, c, SUM(m.value) as lines
WHERE lines = 0
RETURN c.name as _zu_loeschen, c.fqn, p.fqn
"""
pd.DataFrame(graph.data(query))
In [ ]: